home *** CD-ROM | disk | FTP | other *** search
- /* GetDevicePowrInfo.c */
- /*
- * GetDevicePowrInfo.c
- * Copyright © 1994-95 Apple Computer Inc. All rights reserved.
- *
- */
- /* .___________________________________________________________________________________.
- | These routines, after modification, will be useful for other drivers. There are |
- | several general-purpuse routines that simplify access to the Name Registry. There |
- | are also some routines that are specific to the sample driver that will be useful |
- | for other drivers after modification. |
- .___________________________________________________________________________________.
- */
-
- #include "NCRDriverPrivate.h"
- /*
- * IEEE 1275 defines the "power-consumption" property.
- */
- #define kDevicePowerProperty "power-consumption"
- /*
- * Power values are encoded in a vector of "maximum in microwatts." Unspecified values
- * shall be zero if other values are provided. Power consumption is zero for missing
- * values. If the property is missing, the default value will be used.
- */
- enum {
- kUnspecifiedStandby,
- kUnspecifiedFullPower,
- kFiveVoltStandby,
- kFiveVoltFullPower,
- kThreeVoltStandby,
- kThreeVoltFullPower,
- kIOPowerStandby,
- kIOPowerFullPower,
- kReservedStandby,
- kReservedFullPower
- };
-
- /*
- * The function uses this structure to equate registry entry values with
- * DriverGestalt selectors.
- */
- typedef struct PowerInfo {
- OSType driverGestaltSelector;
- short correctIndex;
- short fallbackIndex;
- } PowerInfo;
- static const PowerInfo gPowerInfo[] = {
- { kDriverGestalt5MaxHighPower, kFiveVoltFullPower, kUnspecifiedFullPower },
- { kDriverGestalt5MaxLowPower, kFiveVoltStandby, kUnspecifiedStandby },
- { kDriverGestalt3MaxHighPower, kThreeVoltFullPower, kUnspecifiedFullPower },
- { kDriverGestalt3MaxLowPower, kThreeVoltStandby, kUnspecifiedStandby },
- { 0, 0, 0 }
- };
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Retrieve the driver power consumption vector and search it for the desired power
- * consumption value. Return the desired value, or a default value if the desired
- * value is unavailable. This function does not allocate memory or return any errors.
- */
- UInt32
- GetDevicePowerConsumption(
- RegEntryIDPtr regEntryIDPtr, /* Driver's Name Registery ID */
- OSType driverGestaltSelector, /* PBStatus parameter */
- UInt32 defaultPowerConsumption /* Default return value */
- )
- {
- OSErr status;
- UInt32 result;
- short i;
- short index;
- ItemCount nValues;
- RegPropertyValueSize size;
- UInt32 microWatts[kReservedFullPower];
-
- Trace(GetDevicePowerConsumption);
- result = defaultPowerConsumption;
- status = RegistryPropertyGetSize(
- regEntryIDPtr,
- kDevicePowerProperty,
- &size
- );
- if (status == noErr && size <= sizeof microWatts) {
- status = RegistryPropertyGet(
- regEntryIDPtr,
- kDevicePowerProperty,
- (RegPropertyValue *) microWatts,
- &size
- );
- }
- CheckStatus(status, "\pCan't retrieve power-consumption");
- if (status == noErr) {
- nValues = size / sizeof microWatts[0];
- for (i = 0; gPowerInfo[i].driverGestaltSelector != 0; i++) {
- if (gPowerInfo[i].driverGestaltSelector == driverGestaltSelector) {
- index = gPowerInfo[i].correctIndex;
- if (index >= nValues)
- index = gPowerInfo[i].fallbackIndex;
- if (index < nValues)
- result = microWatts[index];
- break;
- }
- }
- }
- return (result);
- }
-
-
-